package cn.glutnn.service.impl;

import cn.glutnn.entity.Bank;
import cn.glutnn.entity.Finance;
import cn.glutnn.entity.Result;
import cn.glutnn.mapper.BankMapper;
import cn.glutnn.mapper.BankUserMapper;
import cn.glutnn.mapper.FinanceMapper;
import cn.glutnn.service.BankService;
import cn.glutnn.service.BankUserService;
import cn.glutnn.utils.ThreadLocalUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.glutnn.entity.BankUser;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (BankUser)表服务实现类
 *
 * @author msh
 * @since 2024-10-25 09:29:49
 */
@Service("bankUserService")
public class BankUserServiceImpl extends ServiceImpl<BankUserMapper, BankUser> implements BankUserService {


    @Autowired
    private BankMapper bankMapper;
    @Autowired
    private FinanceMapper financeMapper;
    @Override
    public Result<List<BankUser>> selectAllBank() {
        List<BankUser> list = list();
        System.out.println(list);
        return Result.success(list);
    }

    @Override
    public Result<Map<String, Object>> selectBankById(Integer bankId) {

        Map<String, Object> map = new HashMap<>();
        Finance finance= null;
        List<Finance> bankId1 = financeMapper.selectList(new QueryWrapper<Finance>().eq("bank_id", bankId));
        if (bankId1.size() > 0) {
            finance= bankId1.get(0);
        }
        Bank bank = bankMapper.selectOne(new QueryWrapper<Bank>().eq("bank_id", bankId));

        if (finance != null) {
            map.put("name", finance.getRealName());
            map.put("idNum", finance.getIdNum());
            map.put("address", "");
        }
        if (bank != null) {
            map.put("bankName", bank.getBankName());
            map.put("money", bank.getMoney());
            map.put("rate", bank.getRate());
            map.put("repayment", bank.getRepayment());
            map.put("phone", bank.getBankPhone());
            map.put("introduce", bank.getIntroduce());

        }
        System.out.println(map);
        return Result.success(map);
    }


}

